/*
 * @Author: master
 * @Date: 2022-04-04 13:23:37
 * @LastEditTime: 2022-04-06 15:17:28
 * @Description: app
 */
import { defineStore } from 'pinia';
const appStore = defineStore('app', {
  state: () => ({
    theme: localStorage.getItem('theme') || 'light', // 亮色模式
    menuCollapse: false, // 菜单状态
    menuWidth: 220, // 菜单宽度
  }),
  getters: {},
  actions: {
    /**
     * 初始化主题
     */
    initTheme(theme) {
      document.body.setAttribute('arco-theme', theme);
    },
    /**
     * 主题切换
     * @param {String} theme
     */
    toggleTheme(theme) {
      if (theme && theme === 'light') {
        this.theme = 'dark';
        document.body.setAttribute('arco-theme', 'dark');
      } else {
        this.theme = 'light';
        document.body.removeAttribute('arco-theme');
      }
      localStorage.setItem('theme', this.theme);
    },
    /**
     * 更新部分状态
     * @param {Object} partial
     */
    updatePartial(partial) {
      this.$patch(partial);
    },
  },
});
export default appStore;
